home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / jam / jamdisk4 / arptools / src / cwin.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  5KB  |  224 lines

  1. /*
  2.           Cwin - Size the CLI window.
  3.  
  4.           Original effort by Fabio Rossetti.
  5.  
  6.           (c) 1989 by Fabio Rossetti
  7.  
  8.       To compile under Lattice C v5.0x use:
  9.  
  10.         lc -O -cus -v cwin.c
  11.         blink from lib:cres.o cwin.o to cwin lib lib:a.lib lib:lc.lib sd nd
  12.  
  13. */
  14.  
  15. #include <exec/types.h>
  16. #include <exec/ports.h>
  17. #include <exec/io.h>
  18. #include <exec/memory.h>
  19. #include <exec/libraries.h>
  20.  
  21. #include <devices/console.h>
  22. #include <devices/conunit.h>
  23. #include <libraries/dos.h>
  24. #include <libraries/dosextens.h>
  25. #include <libraries/arpbase.h>
  26.  
  27. #include <intuition/intuitionbase.h>
  28. #include <intuition/intuition.h>
  29.  
  30. #include <arpfunctions.h>
  31. #include <proto/exec.h>
  32. #include <proto/intuition.h>
  33.  
  34. struct MsgPort iorp = {
  35.     {0, 0, NT_MSGPORT, 0, 0}, 0,
  36.     -1,                /* initialize signal to -1 */
  37.     0,
  38.                 /* start with empty list */
  39.     {&iorp.mp_MsgList.lh_Tail, 0, &iorp.mp_MsgList.lh_Head, 0, 0}
  40. };
  41.  
  42. struct IOStdReq ior = {
  43.     {{0, 0, 0, 0, 0}, &iorp, 0},
  44.     0                /* device is zero */
  45. };
  46.  
  47. struct Window *W;
  48. struct ArpBase *ArpBase;
  49. struct IntuitionBase *IntuitionBase;
  50.  
  51. VOID Cleanup(code)
  52. {
  53.     if (ior.io_Device != 0) {
  54.     if (iorp.mp_SigBit != -1) {
  55.         FreeSignal(iorp.mp_SigBit);
  56.     }
  57.     CloseDevice(&ior);
  58.     }
  59.     CloseLibrary((struct Library*)ArpBase);  
  60.     exit(code);
  61. }
  62.  
  63. /* bulletproofly obtain a pointer to the CLI window sending a ACTION_DISK_INFO
  64.    packet to the console process and looking into InfoData */
  65. struct Window *GetWin()
  66.  
  67. {
  68.     struct MsgPort *con;
  69.     struct StandardPacket *packet=NULL;
  70.     struct InfoData *id=NULL;
  71.  
  72.     /* open the console device */
  73.     if ((OpenDevice("console.device", -1, &ior, 0)) != 0) {
  74.     Cleanup(RETURN_FAIL);
  75.     }
  76.  
  77.     /* set up the message port in the I/O request */
  78.     if ((iorp.mp_SigBit = AllocSignal(-1)) < 0) {
  79.     Cleanup(RETURN_FAIL);
  80.     }
  81.     iorp.mp_SigTask = (struct Task*)FindTask(NULL);
  82.  
  83.     /* try to find console associated with calling process */
  84.     /* if started from CLI, than is  */
  85.     if ((iorp.mp_SigTask->tc_Node.ln_Type == NT_PROCESS)) {
  86.     con = (struct MsgPort *) 
  87.         ((struct Process *) iorp.mp_SigTask) -> pr_ConsoleTask;
  88.     if (con != 0) {
  89.         if ((packet = (struct StandardPacket *)
  90.             ArpAlloc(sizeof(*packet)))) {
  91.         if ((id = (struct id *) ArpAlloc(sizeof(*id)))) {
  92.             /* this is the console handlers packet port */
  93.             packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt);
  94.             packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  95.             packet->sp_Pkt.dp_Port = &iorp;
  96.             packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  97.             packet->sp_Pkt.dp_Arg1 = ((ULONG) id) >> 2;
  98.             PutMsg(con, packet);
  99.              WaitPort(&iorp);
  100.             /* Pointer to console window, all we need..*/
  101.             return( (struct Window*)(id->id_VolumeNode));
  102.         }
  103.     }
  104.     }
  105.     /* error */
  106.     return((struct Window *)-1);
  107. }
  108. }
  109.  
  110. VOID MemCleanup()
  111. {
  112. }
  113.  
  114. VOID _main(Line)
  115.  
  116. STRPTR Line;
  117.  
  118. {
  119.     
  120.  
  121.     
  122.     LONG argc,val;
  123.     STRPTR argv[7];
  124.     WORD sdx=0,sdy=0,mdx=0,mdy=0;
  125.  
  126.     if(!(ArpBase = (struct ArpBase*)OpenLibrary(ArpName,ArpVersion))) exit(20);
  127.     
  128.     IntuitionBase = ArpBase->IntuiBase;
  129.  
  130.     /* parse command line */
  131.     for (argc=0;argc < 7;++argc)
  132.         argv[argc] = (STRPTR) NULL;
  133.  
  134.     while(*Line > ' ')
  135.         ++Line;
  136.  
  137.     argc = GADS(++Line,
  138.             strlen(Line),
  139. "\nUsage: Cwin BIG=B | SMALL=S | INFO=I\n       Cwin LeftEdge|# TopEdge|# Width|MAX|# Height|MAX|#\n",
  140.             argv,
  141. "BIG=B/S,SMALL=S/S,INFO=I/S,LEFTEDGE,TOPEDGE,WIDTH,HEIGHT");
  142.  
  143.     if ((W = GetWin()) == (struct Window *)-1) Cleanup(RETURN_FAIL);
  144.  
  145.         if (argv[2]) {
  146.         /* There will be a 16384^2 Amiga :) ?
  147.            Cwin will be there anyway...*/
  148.         Printf("%05ld %05ld %05ld %05ld %s\n",
  149.             W->LeftEdge,
  150.             W->TopEdge,
  151.             W->Width,
  152.             W->Height,
  153.             W->Title);
  154.         Cleanup(RETURN_OK);
  155.             }
  156.  
  157.     
  158.         /* expand window */
  159.         if (argv[0]) {
  160.         MoveWindow(W,(-W->LeftEdge),(-W->TopEdge));
  161.         Delay(7);
  162.         SizeWindow(W,(((W->WScreen)->Width)-(W->Width)),
  163.             (((W->WScreen)->Height)-(W->Height)));
  164.  
  165.         WindowToFront(W);
  166.         Cleanup(RETURN_OK);
  167.  
  168.         }
  169.  
  170.         /* iconify window */
  171.         if (argv[1])
  172.  
  173.         {
  174.  
  175.         SizeWindow(W,((W->MinWidth)-(W->Width)),
  176.             ((W->MinHeight)-(W->Height)));
  177.     Cleanup(RETURN_OK);
  178.                 
  179.         }
  180.  
  181.     /* size window */
  182.     if (argc > 3) {
  183.     
  184.         /* leftedge */
  185.         val = Atol(argv[3]);    
  186.         if (!(Errno==ERRBADINT) && (val >= 0) && 
  187.             (val+W->Width <= W->WScreen->Width)) 
  188.             mdx = val-W->LeftEdge;
  189.             Errno = NULL;
  190.  
  191.         val = Atol(argv[4]);    
  192.         if (!(Errno==ERRBADINT) && (val >= 0) && 
  193.             (val+W->Height <= W->WScreen->Height)) 
  194.             mdy = val-W->TopEdge;
  195.             Errno = NULL;
  196.     
  197.         if (Strcmp(argv[5],"MAX")) {
  198.         val = Atol(argv[5]);    
  199.         if (!(Errno==ERRBADINT) && (val >= W->MinWidth) && 
  200.             (val+W->LeftEdge <= W->WScreen->Width))
  201.             sdx = val-W->Width;
  202.         Errno = NULL;
  203.             }
  204.         else sdx = (((W->WScreen)->Width)-(W->Width));
  205.     
  206.     if (Strcmp(argv[6],"MAX")) {
  207.         val = Atol(argv[6]);    
  208.     if (!(Errno==ERRBADINT) && (val >= W->MinHeight) && 
  209.             (val+W->TopEdge <= W->WScreen->Height))
  210.             sdy = val-W->Height;
  211.         Errno = NULL;
  212.             }
  213.     else sdy = (((W->WScreen)->Height)-(W->Height));
  214.         MoveWindow(W,mdx,mdy);
  215.         Delay(7);
  216.         SizeWindow(W,sdx,sdy);
  217.     
  218.          }   
  219.         else Puts("Error: Too few arguments");                            
  220.         
  221.     Cleanup(RETURN_OK);
  222. }
  223.  
  224.